<?php
$css = ['/assets/jedate/skin/jedate.css'];
$this->load->view('admin/layout/head', array('title'=>'统计分析','nav'=>'ustatistics','css'=>$css), FALSE);
?>
<style media="screen">
	.table {
		position: fixed;
	    padding: 20px;
	    top: 0;
	    left: 0;
	    bottom: 0;
	    right: 0;
	    width: 100%;
	    background: rgba(0, 0, 0, 0.8);
	    height: 100%;
	    z-index: 222222;
	}

	.hidden {
		display: none;
	}

	.table table {
		width: 700px;
		margin-left: auto;
		margin-right: auto;
		background: #fff;
		max-height: 500px;
		overflow: auto;
	}

	.table table tr {
		border: 1px solid;
	}

	.table table th, .table table td {
		text-align: center;
		padding: 4px 12px;
	}

	.table .close1 {
		background: #fff;
	    position: absolute;
	    right: 10px;
	    top: 10px;
	    font-size: 20px;
	    border-radius: 50%;
	    width: 25px;
	    height: 25px;
	    line-height: 25px;
	}
</style>
<div id="container">
	<div class="panel panel-default">
		<div class="panel-heading">
			今日交易统计
			<button class="btn btn-info search-btn" style="float:right">搜索</button>
			<input type="text" name="day" class="form-control date-picker" value="<?= $this->input->get('day') ?>" placeholder="选择日期搜索" style="width:120px; float: right;">


		</div>
		<div class="panel-body today-top">
		    <div class="row">
		    	<div class="col-sm-2 has-table">
		    		<b><?php echo $total ?></b>
		    		<span>交易总额</span>
					<div class="table hidden">
						<div class="close1">
							x
						</div>
						<table>
							<thead>
								<tr>
									<th>订单号</th>
									<th>金额</th>
									<th>时间</th>
								</tr>
							</thead>
							<tbody>
								<?php foreach ($total_detail as $key => $value): ?>
									<tr>
										<td><?= $value['order_id'] ?></td>
										<td><?= $value['total'] ?></td>
										<td><?= explode(' ', $value['create_time'])[0] ?></td>
									</tr>
								<?php endforeach; ?>
							</tbody>
						</table>
					</div>
		    	</div>
		    	<div class="col-sm-2 has-table">
		    		<b><?php echo $online ?></b>
		    		<span>线上交易</span>
					<div class="table hidden">
						<table>
							<thead>
								<tr>
									<th>订单号</th>
									<th>金额</th>
									<th>时间</th>
								</tr>
							</thead>
							<tbody>
								<?php foreach ($online_detail as $key => $value): ?>
									<tr>
										<td><?= $value['order_id'] ?></td>
										<td><?= $value['total'] ?></td>
										<td><?= explode(' ', $value['create_time'])[0] ?></td>
									</tr>
								<?php endforeach; ?>
							</tbody>
						</table>
					</div>
		    	</div>
		    	<div class="col-sm-2 has-table">
		    		<b><?php echo $offline ?></b>
		    		<span>线下交易</span>
					<div class="table hidden">
						<div class="close1">
							x
						</div>
						<table>
							<thead>
								<tr>
									<th>订单号</th>
									<th>金额</th>
									<th>时间</th>
								</tr>
							</thead>
							<tbody>
								<?php foreach ($offline_detail as $key => $value): ?>
									<tr>
										<td><?= $value['order_id'] ?></td>
										<td><?= $value['total'] ?></td>
										<td><?= explode(' ', $value['create_time'])[0] ?></td>
									</tr>
								<?php endforeach; ?>
							</tbody>
						</table>
					</div>
		    	</div>
		    	<div class="col-sm-2 has-table">
		    		<b><?php echo $refund_fee ?></b>
		    		<span>退款总额</span>
					<div class="table hidden">
						<div class="close1">
							x
						</div>
						<table>
							<thead>
								<tr>
									<th>充值金额</th>
									<th>订单号/描述</th>
									<th>时间</th>
								</tr>
							</thead>
							<tbody>
								<?php foreach ($charge_detail as $key => $value): ?>
									<tr>
										<td><?= $value['num'] ?></td>
										<td><?= $value['desc'] ?></td>
										<td><?= explode(' ', $value['create_time'])[0] ?></td>
									</tr>
								<?php endforeach; ?>
							</tbody>
						</table>
					</div>
		    	</div>
		    	<div class="col-sm-2 has-table">
		    		<b><?php echo $charge?$charge:0 ?></b>
		    		<span>充值金额</span>
					<div class="table hidden">
						<div class="close1">
							x
						</div>
						<table>
							<thead>
								<tr>
									<th>充值金额</th>
									<th>订单号/描述</th>
									<th>时间</th>
								</tr>
							</thead>
							<tbody>
								<?php foreach ($charge_detail as $key => $value): ?>
									<tr>
										<td><?= $value['num'] ?></td>
										<td><?= $value['desc'] ?></td>
										<td><?= explode(' ', $value['create_time'])[0] ?></td>
									</tr>
								<?php endforeach; ?>
							</tbody>
						</table>
					</div>
		    	</div>
		    	<div class="col-sm-2 has-table">
		    		<b><?php echo $vat?$vat:0 ?></b>
		    		<span>VAT税费</span>
					<div class="table hidden">
						<div class="close1">
							x
						</div>
						<table>
							<thead>
								<tr>
									<th>商品名称</th>
									<th>数量</th>
									<th>税费</th>
									<th>合计</th>
								</tr>
							</thead>
							<tbody>
								<?php foreach ($vat_detail as $key => $value): ?>
									<tr>
										<td><?= $value['title'] ?></td>
										<td><?= $value['qty'] ?></td>
										<td><?= $value['tax'] ?></td>
										<td><?= round($value['tax']*$value['qty'], 2) ?></td>
									</tr>
								<?php endforeach; ?>
							</tbody>
						</table>
					</div>
		    	</div>
		    </div>
		</div>
	</div>
	<div class="panel panel-default">
		<div class="panel-heading">
			今日收入统计
		</div>
		<div class="panel-body">
			<div id="pie-charts" style="width: 400px; height: 400px; float: left;">

			</div>
		    <div style="margin-left:500px" class="today-number">

		    	<?php foreach ($sr as $k=>$s): ?>
		    	<?php if($k==7) continue; ?>
		    	<div>
		    		<b><?php echo  isset($s['money'])?$s['money']:0 ?></b>
		    		<span><?= $s['chinese'] ?></span>
		    	</div>
		    	<?php endforeach ?>
		    	<div>
		    		<a href="/admin/refund/index?pay_mode=1&start_date=<?php echo $today ?>&end_date=<?php echo $today ?>">
		    		<b><?php echo $refund_balance ?></b>
		    		<span>会员卡退款</span>
		    		</a>
		    	</div>
		    	<div>
		    		<a href="/admin/refund/index?pay_mode=1&start_date=<?php echo $today ?>&end_date=<?php echo $today ?>">
		    		<b><?php echo $refund_cash ?></b>
		    		<span>现金退款</span>
		    		</a>
		    	</div>
		    </div>
		</div>
	</div>
</div>


<?php
$this->load->view('admin/layout/footer',['js'=>['/assets/echarts/echarts.common.min.js','/assets/jedate/jedate.min.js']]);
?>
<script type="text/javascript">
datepicker('.date-picker','<?php echo $this->session->admin_language ?>');

$(function () {
	$(".has-table").on('click', function (e) {
		if (e.target === this)
			$(this).find('.table').removeClass('hidden');
	});
	$(".table .close1").on('click', function () {
		$(this).parents('.table').addClass('hidden');
	})
});

$('.search-btn').click(function(event) {
	if($('[name=day]').val()){
		window.location = '/admin/ustatistics/today?day='+$('[name=day]').val()
	}
});

	<?php
	$legend_data = '';
	$series_data = '';
	foreach ($sr as $key => $value) {
		if($key == 7) continue;
		if(!isset($value['money']) || $value['money'] == 0) continue;
		if($legend_data) $legend_data.=',';
		$legend_data .="'".$value['chinese']."'";
		if($series_data) $series_data.=',';
		$series_data .="{value:".(isset($value['money'])?$value['money']:0).",name:'".$value['chinese']."'}";
	}
	?>

option = {

    tooltip : {
        trigger: 'item',
        formatter: "{b} : {c} ({d}%)"
    },

    series: [
        {
            name:'访问来源',
            type:'pie',
            radius: ['50%', '70%'],
            avoidLabelOverlap: false,
            label: {
                normal: {
                    show: false,
                    position: 'center'
                },
                emphasis: {
                    show: true,
                    textStyle: {
                        fontSize: '30',
                        fontWeight: 'bold'
                    }
                }
            },
            labelLine: {
                normal: {
                    show: false
                }
            },
            data:[<?php echo $series_data ?>]
        }
    ]
};

$(function(){
	var myChart = echarts.init(document.getElementById('pie-charts'));
	myChart.setOption(option);
})

</script>
